#!/bin/sh

read -p "gituser: " gituser
read -p "gitpass: " gitpass

/usr/bin/expect <<EOF
set timeout -1
spawn git pull
expect {
"Username" { send "$gituser\r"; exp_continue;  }
"Password" { send "$gitpass\r"; exp_continue;  }
eof
}
EOF

for s in `git submodule | awk '{print $2}'`; do
	echo -e "\nUPDATEING $s..."
    cd $s
    echo git switch master -f
    git switch master -f
    expect <<-EOF
set timeout -1
spawn git pull
expect {
"Username" { send "$gituser\r"; exp_continue; }
"Password" { send "$gitpass\r";   exp_continue; }
eof
}
EOF
    expect <<-EOF
set timeout -1
spawn git submodule update --init --recursive
expect {
"Username" { send "$gituser\r"; exp_continue; }
"Password" { send "$gitpass\r";   exp_continue; }
eof
}
EOF
    cd -
done
